package com.cashbook.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cashbook.mapper.TbRemindMapper;
import com.cashbook.pojo.TbAdmin;
import com.cashbook.pojo.TbRemind;
import com.cashbook.pojo.TbRemindExample;
import com.cashbook.pojo.TbRemindExample.Criteria;
import com.cashbook.service.RemindService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import entity.PageResult;
@Service
public class RemindServiceImpl implements RemindService{
	@Autowired
	TbRemindMapper remindMapper;
	/**
	 * 查询全部
	 */
	@Override
	public List<TbRemind> findAll() {
		return remindMapper.selectByExample(null);
	}
	/**
	 * 分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		Page<TbRemind> page=	(Page<TbRemind> ) remindMapper.selectByExample(null);
		return  new PageResult(page.getTotal(), page.getResult());
	}
	/**
	 * 添加
	 */
	@Override
	public void add(TbRemind remind) {
		remindMapper.insert(remind);
		
	}
	/**
	 * 更新
	 */
	@Override
	public void update(TbRemind remind) {
		remindMapper.updateByPrimaryKey(remind);
		
	}
	/**
	 * 根据主键查询
	 */
	@Override
	public TbRemind findOne(Long id) {
		return remindMapper.selectByPrimaryKey(id);
	}
	/**
	 * 批量删除  
	 */
	@Override
	public void delete(Long[] ids) {
		for(Long id:ids) {
			remindMapper.deleteByPrimaryKey(id);
		}
		
	}

	@Override
	public PageResult findPage(TbRemind remind, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		TbRemindExample example=new TbRemindExample();
		Criteria criteria=example.createCriteria();
		if(remind!=null) {
			if(remind.getContent()!=null && remind.getContent().length()>0) {
				criteria.andContentLike("%"+remind.getContent()+"%");
			}
			if(remind.getOpenId()!=null && remind.getOpenId().length()>0) {
				criteria.andOpenIdLike("%"+remind.getOpenId()+"%");
			}
			if(remind.getStatus()!=null) {
				criteria.andStatusEqualTo(remind.getStatus());
			}
			if(remind.getTime()!=null) {
				criteria.andTimeEqualTo(remind.getTime());
			}
		}
		Page<TbRemind> page= (Page<TbRemind>)remindMapper.selectByExample(example);		
		return new PageResult(page.getTotal(), page.getResult());
	}
	
}
